import sqlite3
import sys

if not sys.argv[1:]:
  print "Usage: %s <mycampus.sq3 path>" % sys.argv[0]
  sys.exit(0)
else:
  filename = sys.argv[1]

db = sqlite3.connect(filename)
c = db.cursor()
c.execute("""
  select code, title, count(T.id)
  from courses C join sections S on C.code = S.course
                 join schedules T on T.section_id = S.id
  group by code, title
  """)
for (course, title, count) in c.fetchall():
  print "%8s %s : meets %d times in a week" % (course, title.ljust(40), count)

db.close()
